package cn.cas.mango.util.ResponseUtil;

import cn.cas.mango.service.ConfigService;
import cn.cas.mango.util.string.StringUtils;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.util.Strings;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class ResponseUtil {


  public static Set<String> wrappedKeyword(Object key) {
    Set<String> keywords = new LinkedHashSet<>();
    try {
      if (key != null) {
        if (key instanceof List) {
          List<Object> keyList = (List<Object>) key;
          if (!keyList.isEmpty()) {
            Object o = keyList.get(0);
            if (o instanceof String) {
              keywords.addAll((List)keyList);
            } else {
              List<String> collect = keyList.stream()
                  .map(x -> (String) ((Map) x).get("name"))
                  .collect(Collectors.toList());
              keywords.addAll(collect);
            }
          }
        } else {
          if (key instanceof Map) {
            keywords.add((String) ((Map) key).get("name"));
          } else {
            keywords.add((String) key);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return keywords;
  }
}
